package com.stock.util;

import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @author admin
 * @since 2023-03-31
 * @description
 */
@Component
public class GetCurrentTime {
    public String getCurrentTimeBySecond() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
        return formatter.format(date);
    }

    public String getCurrentTimeByDay() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(System.currentTimeMillis());
        return formatter.format(date);
    }

    public String getCurrentId() {
        Random random = new Random();
        double v = random.nextDouble() * 100000;
        String s = (v + "").replaceAll("\\.", "");
        return System.currentTimeMillis() + "" + s.substring(0, 6);
    }
}
